/* This file is part of MyRename
 * Copyright (C) 2005-2009 Kai-Chieh Ku (kjackie@gmail.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#pragma once

#include "filename.h"

typedef CString&(*transfunc)(CString&, const CString&, const bool);
typedef int(*strcmpfunc)(LPCTSTR, LPCTSTR);

#define MAXCOL 2

enum {
	FLC_REDRAW = 1
};

// CFileListCtrl
class CFileListCtrl : public CListCtrl
{
	DECLARE_DYNAMIC(CFileListCtrl)

public:
	CFileListCtrl();
	virtual ~CFileListCtrl();
	virtual void Init();
	virtual void Localize();
	void SetColumns(CUIntArray *order, CUIntArray *width);
	void CreateList(LPCTSTR path, const CFileName *mask = NULL);
	void CreateList(const CFileListCtrl &src, transfunc trfun = NULL);
	bool SortList(int col = -1);
	void SortList(int col, bool bAsc);
	void ReverseList();
	void InsertItem(LPCTSTR name, uint16 attr, int iIcon, int nItem = -1);
	void SetSortArrow(int nCol, bool bAsc);
	void Synchronize();
	void RedrawVisible();

	int m_sCol;
	bool m_sAsc;
	CFileListCtrl *m_pFriendList;
protected:
	virtual void UpdateMenu();
	static int CALLBACK ColCmp(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);

	CImageList m_itemImg;
	CImageList m_colImg;
	CHeaderCtrl *m_pHeader;
	CUIntArray *m_pColOrder;
	CUIntArray *m_pColWidth;
	CMenu m_context;
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnDestroy();
	afx_msg void OnSetFocus(CWnd* pOldWnd);
	afx_msg void OnKillFocus(CWnd* pNewWnd);
	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
	afx_msg void OnEditCopy();
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
	afx_msg void OnLvnGetDispInfo(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnLvnDeleteitem(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
//overrides
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
protected:
	virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
	virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
};
